$(function(){
	
	
	$("#aid").val(aid);
	
	var files = [];
	
	$("#photo").change(function(){
		
		var file = this.files[0];
		
		files.push(file);
		
		//文件预览
		//1.创建一个fileReader对象
		var fileReader = new FileReader();
		//2.定义fileReader的onload方法
		fileReader.onload = function(e){
			var base64 = e.target.result;
			console.log(base64);
			$("#photos").append('<img class="addedphoto" src="'+base64+'"/>');
		}
		//3.读取图片
		fileReader.readAsDataURL(file);
	});
	
	$("#btn_baoming").click(function(){
		
		var formDate = new FormData(document.getElementById("myform"));
		
		for(var i=0; i<files.length;i++){
			formDate.append("upload",files[i]);
		}
		
		$.ajax({
			url:"candidates",
			type:"post",
			data:formDate,
			dataType:"json",
			contentType:false,
			processData:false,
			cache:false,
			success:function(data){
				if(data.result){
					alert("报名成功！");
					location.href = "index.html?aid="+aid;
				}else{
					alert("报名失败！");
					location.href = "baoming.html?aid="+aid;
				}
			}
			
		});
	});
	
})